export default () => {
  return new Promise((resolve, reject) => {
    if (window.AMap) {
      resolve(window.AMap)
    } else {
      //  <script src="https://webapi.amap.com/maps?v=1.4.12&key=507de00c91710cf81bb0e7a2cfc26263"></script>
      const aMapScript = document.createElement('script')
      aMapScript.type = 'text/javascript'
      aMapScript.async = true
      aMapScript.src =
        'https://webapi.amap.com/maps?v=1.4.12&key=507de00c91710cf81bb0e7a2cfc26263'
      aMapScript.onerror = reject
      document.head.appendChild(aMapScript)
      aMapScript.onload = () => {
        resolve(window.AMap)
      }
    }
  })
}
